<template>
  <div class="login-container">
    <div class="background-effect">
      <div class="grid"></div>
      <div class="circles">
        <div v-for="n in 10" :key="n" class="circle"></div>
      </div>
    </div>
    <div class="login-box">
      <div class="login-box-effect"></div>
      <div class="login-header">
        <div class="title-icon">
          <i class="el-icon-monitor"></i>
        </div>
        <h2>合肥市网络舆情可视化系统</h2>
        <div class="header-decoration"></div>
      </div>
      <el-form :model="loginForm" :rules="rules" ref="loginForm" class="login-form">
        <el-form-item prop="username">
          <el-input 
            v-model="loginForm.username" 
            prefix-icon="el-icon-user"
            placeholder="用户名">
          </el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input 
            v-model="loginForm.password" 
            prefix-icon="el-icon-lock"
            type="password"
            placeholder="密码"
            @keyup.enter.native="handleLogin">
          </el-input>
        </el-form-item>
        <el-form-item>
          <el-button 
            type="primary" 
            :loading="loading"
            class="login-button"
            @click="handleLogin">
            <span class="button-content">
              {{ loading ? '登录中...' : '登录' }}
              <i class="el-icon-right"></i>
            </span>
          </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Login',
  data() {
    return {
      loginForm: {
        username: '',
        password: ''
      },
      loading: false,
      rules: {
        username: [
          { required: true, message: '请输入用户名', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    handleLogin() {
      this.$refs.loginForm.validate(valid => {
        if (valid) {
          this.loading = true
          // 这里模拟登录请求
          setTimeout(() => {
            if (this.loginForm.username === 'admin' && this.loginForm.password === 'admin') {
              localStorage.setItem('token', 'demo-token')
              this.$message.success('登录成功')
              this.$router.push('/dashboard')
            } else {
              this.$message.error('用户名或密码错误')
            }
            this.loading = false
          }, 1000)
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.login-container {
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  background: #0f1c3c;
  position: relative;
  overflow: hidden;
  
  .background-effect {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    
    .grid {
      position: absolute;
      width: 200%;
      height: 200%;
      background-image: 
        linear-gradient(rgba(24, 144, 255, 0.1) 1px, transparent 1px),
        linear-gradient(90deg, rgba(24, 144, 255, 0.1) 1px, transparent 1px);
      background-size: 20px 20px;
      transform: rotate(45deg);
      animation: gridMove 15s linear infinite;
    }
    
    .circles {
      position: absolute;
      width: 100%;
      height: 100%;
      
      .circle {
        position: absolute;
        border: 2px solid rgba(24, 144, 255, 0.1);
        border-radius: 50%;
        animation: circleFloat 10s infinite;
        
        @for $i from 1 through 10 {
          &:nth-child(#{$i}) {
            width: #{random(100)}px;
            height: #{random(100)}px;
            left: #{random(100)}vw;
            top: #{random(100)}vh;
            animation-delay: #{random(5)}s;
            animation-duration: #{5 + random(5)}s;
          }
        }
      }
    }
  }
  
  .login-box {
    width: 400px;
    padding: 30px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
    backdrop-filter: blur(10px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    position: relative;
    border: 1px solid rgba(255, 255, 255, 0.1);
    
    &::before {
      content: '';
      position: absolute;
      top: -2px;
      left: -2px;
      right: -2px;
      bottom: -2px;
      background: linear-gradient(45deg, 
        rgba(24, 144, 255, 0.3),
        transparent,
        rgba(24, 144, 255, 0.3)
      );
      border-radius: 11px;
      z-index: -1;
      animation: borderLight 3s linear infinite;
    }
    
    .login-header {
      text-align: center;
      margin-bottom: 30px;
      position: relative;
      
      .title-icon {
        font-size: 40px;
        color: #1890ff;
        margin-bottom: 15px;
        animation: iconFloat 3s ease-in-out infinite;
        
        i {
          background: linear-gradient(45deg, #1890ff, #40a9ff);
          -webkit-background-clip: text;
          -webkit-text-fill-color: transparent;
        }
      }
      
      h2 {
        color: #fff;
        font-size: 24px;
        margin: 0;
        font-weight: 600;
        text-shadow: 0 0 10px rgba(24, 144, 255, 0.3);
        letter-spacing: 2px;
        background: linear-gradient(to right, #ffffff, #88c4ff);
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
      }
      
      .header-decoration {
        margin: 10px auto 0;
        width: 60%;
        height: 2px;
        background: linear-gradient(to right,
          transparent,
          rgba(24, 144, 255, 0.8),
          #1890ff,
          rgba(24, 144, 255, 0.8),
          transparent
        );
      }
    }
    
    .login-form {
      :deep(.el-input) {
        .el-input__inner {
          background: rgba(24, 144, 255, 0.1);
          border: 1px solid rgba(255, 255, 255, 0.2);
          color: #fff;
          height: 45px;
          transition: all 0.3s;
          
          &::placeholder {
            color: rgba(255, 255, 255, 0.5);
          }
          
          &:focus {
            border-color: #1890ff;
            box-shadow: 0 0 10px rgba(24, 144, 255, 0.2);
          }
        }
        
        .el-input__prefix {
          color: rgba(255, 255, 255, 0.7);
          font-size: 18px;
        }
      }
      
      .login-button {
        width: 100%;
        border-radius: 4px;
        background: #1890ff;
        border: none;
        padding: 12px 20px;
        font-size: 16px;
        position: relative;
        overflow: hidden;
        transition: all 0.3s;
        
        .button-content {
          display: flex;
          align-items: center;
          justify-content: center;
          gap: 8px;
        }
        
        &:hover {
          background: linear-gradient(45deg, #1890ff, #40a9ff);
          transform: translateY(-1px);
          box-shadow: 0 5px 15px rgba(24, 144, 255, 0.3);
          
          &::after {
            transform: translateX(100%);
          }
        }
        
        &::after {
          content: '';
          position: absolute;
          top: 0;
          left: -100%;
          width: 100%;
          height: 100%;
          background: linear-gradient(
            90deg,
            transparent,
            rgba(255, 255, 255, 0.2),
            transparent
          );
          transition: transform 0.5s;
        }
      }
    }
  }
}

@keyframes gridMove {
  0% {
    transform: rotate(45deg) translate(0, 0);
  }
  100% {
    transform: rotate(45deg) translate(-20px, -20px);
  }
}

@keyframes circleFloat {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-20px);
  }
}

@keyframes borderLight {
  0%, 100% {
    opacity: 0.5;
  }
  50% {
    opacity: 1;
  }
}

@keyframes iconFloat {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-10px);
  }
}
</style> 